13. Related Tables
Related Tables
arst
Here are the tables from this video.
The pictures table stores the names of cute animals and the filenames of their pictures.
| id | name | filename |
|---|---|---|
| 1 | Fluffy | fluffsocute.jpg |
| 2 | Monster | monstie-basket.png |
| 3 | George | george.jpg |
| … | … | … |
The votes table stores information about which pictures have been displayed together, and which one the user voted for:
| left | right | winner |
|---|---|---|
| 2 | 3 | 3 |
| 1 | 3 | 1 |
| 2 | 1 | 1 |
| 3 | 2 | 3 |
| 3 | 1 | 1 |
| 2 | 3 | 3 |
| … | … | … |
We can ask the database to join these tables, to look up the animal names for each of the votes:
| left_name | right_name | winner_name |
|---|---|---|
| Monster | George | George |
| Fluffy | George | George |
| Monster | Fluffy | Fluffy |
| George | Monster | George |
| George | Fluffy | Fluffy |
| Monster | George | George |
| … | … | … |